package com.xbang.attendance.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xbang.attendance.entity.system.MaintenanceStation;
import com.xbang.attendance.service.MaintenanceStationService;
import com.xbang.core.dao.support.GenericDaoSupport;
import com.xbang.core.service.impl.BaseServiceImpl;

/**
 * @author huawei
 * @email alonelaval@gmail.com
 */
@Service("mainternaceStationService")
public class MaintenanceStationServiceImpl extends BaseServiceImpl implements MaintenanceStationService {

	@Autowired
	private GenericDaoSupport genericDaoSupport;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.xbang.attendance.service.MaintenanceStationService#checkMaintenanceStation(java.lang.String)
	 */
	public Boolean checkMaintenanceStation(String code) throws Exception {
		StringBuilder sBuilder = new StringBuilder();
		sBuilder.append("SELECT COUNT(1) FROM maintenance_station WHERE  number = ?");
		int i = genericDaoSupport.getJdbcTemplate().queryForInt(sBuilder.toString(), code);
		return i > 0;
	}

	@Override
	public MaintenanceStation getMaintenanceStationByNumber(String number) throws Exception {
		return (MaintenanceStation) genericDaoSupport.getHibernateTemplate().find("From MaintenanceStation m where m.number = ?", number).get(0);
	}

	@Override
	public MaintenanceStation getMaintenanceStationById(Integer id)
			throws Exception {
		return (MaintenanceStation) super.get(MaintenanceStation.class, id);
	}
}
